/**
 * FileName: AbstractService
 * Author: TangZaoBang
 * Date: 2023/04/29 22:40
 * Description:
 * <p>
 * History:
 * <author> TangZaoBang
 * <time> 2023/04/29 22:40
 * <version> 1.0.0
 * <desc> 版本描述
 */

package com.bosssoft.quickstart.demo.service;

import com.bosssoft.quickstart.demo.base.BaseEntity;
import com.bosssoft.quickstart.demo.constant.GlobalConstant;

import java.time.LocalDate;


/**
 * @Class AbstractService
 * @Description
 * @Author TangZaoBang
 * @Date 2023/04/29 22:40
 * @Version
 */
public abstract class AbstractService {

    public enum OperateType{
        //添加，更新
        ADD,
        UPDATE
    }
    protected void initCommonField(BaseEntity baseEntity, OperateType operateType){
        if(operateType==OperateType.ADD){
            if(baseEntity.getCreatedBy()==null){
                baseEntity.setCreatedBy(GlobalConstant.DEFAULT_CREATOR_ID);
                baseEntity.setUpdatedBy(GlobalConstant.DEFAULT_MODIFIER_ID);
            }
            if(baseEntity.getCreatedTime()==null){
                baseEntity.setCreatedTime(LocalDate.now());
                baseEntity.setUpdatedTime(LocalDate.now());
            }

        }
    }
}
